public class Demo11 {
    public static void main(String[] args) {
        Thread thread1 = new Thread(() -> {
            for (int i = 0; i < 5; ++i) {
                System.out.println("hello thread1");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }
            System.out.println("thread1 结束了");
        });

        Thread thread2 = new Thread(() -> {
            for (int i = 0; i < 3; ++i) {
                System.out.println("hello thread2");
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

            try {
                thread1.join();
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }

            System.out.println("thread2 结束了");
        });

        thread1.start();
        thread2.start();
    }
}
